"""author: songzhiqiang
   data: 2021/11/14
   project: 2021-10-28-弹珠游戏
"""
import string


def passwd_length(str):
    if len(str) < 8:
        return 0
    else:
        return 1


def passwd_compose(str):
    up = 0
    low = 0
    number = 0
    symbol = 0
    for i in str:
        if i.isdigit():
            number = 1
        elif i.isupper():
            up = 1
        elif i.islower():
            low = 1
        else:
            symbol = 1
    sum = up + low + number + symbol
    if sum >= 3:
        return 1
    else:
        return 0


def passwd_len(str):
    for i in range(len(str)):
        if str.count(str[i:i + 3]) >= 2:
            return 0
        else:
            return 1


def userverify():
    lst2 = []
    flag = True
    while flag:
        lst = []
        username = input("请输入你的用户名")
        passwd = input("请输入你的密码")
        # print(passwd_len(passwd))
        # print(passwd_compose(passwd))
        # print(passwd_length(passwd))
        add = 0
        add = passwd_len(passwd) + passwd_compose(passwd) + passwd_length(passwd)

        if passwd_len(passwd) and passwd_length(passwd) and passwd_compose(passwd):
            print(f"密码注册成功")
            lst2.append(username)
            lst2.append(passwd)
            lst.append("very nice")
            flag = False
            print(lst2)
        else:
            if passwd_len(passwd) == 0:
                lst.append("有长度超过或等于3的子串重复")
            if passwd_compose(passwd) == 0:
                lst.append("大、小写字母.数字.其它符号少于三个")
            if passwd_length(passwd) == 0:
                lst.append("密码长度小于八位")
        print(f"密码评分为{2 + add},{lst}")
    num = 0
    while num < 3:
        num += 1
        username = input("请输入用户名\n")
        password = input("请输入密码\n")
        if username in lst2 and password in lst2:
            print("登录成功")
            break
        elif num == 3:
            pass
        else:
            print("登陆失败,请重新登录")
            print(f"还剩{3 - num}次")
    else:
        print("您输入密码超过三次,请稍后重试")


def simpleUI():
    print("-" * 50)
    print('#' + "{0:^42}".format("欢迎登录三乐购物系统") + '#')
    print("-" * 50)


def sum():
    add = 0
    for i in cost:
        add += i
        return add


# userverify()
#
# simpleUI()

goods = [
    {'name': '鼠标', 'price': '10'},
    {'name': '飞机', 'price': '50'},
    {'name': '游艇', 'price': '20'},
    {'name': '火箭', 'price': '250'},
    {"name": '叉子', "price": '18'},
]

money = input('请输入您的金额:')
shop_car = []
cost = []
good = []
new_money = 0

if money.isdigit():
    # 判断输入的金额是否为数字
    while 1:
        for i in range(len(goods)):
            print(i + 1, goods[i]['name'], goods[i]['price'])
            # 打印商品表单

        choose = input('请输入您要购买的商品序号(q结算)：')
        if choose.isdigit() and 0 < int(choose) <= len(goods):
            # print(goods[int(choose) - 1]["name"])
            index_goods = int(choose) - 1
            good.append(goods[index_goods]["name"])
            print(f"您购买了{good}")
            # if shop_car  ==  None:
            #     shop_car[int(choose) -1] = 1
            #     print(shop_car)
            # else:
            #     shop_car[int(choose) -1] += 1
            #     print(shop_car)
            cost.append(int(goods[index_goods]["price"]))
            # print(cost)
            add = 0
            # new_money = 0

            for i in cost:
                add += i
            new_money = int(money) - add
            # print(add)
            # print(new_money)
            if new_money < 0:
                print("您的钱不够了")
            else:
                print(f"您还剩{new_money}")

        elif choose.upper() == 'Q':
            if new_money <= int(money):
                print(f'您此次共消费{int(money) - new_money},余额{new_money}')
            break

        else:
            print("您输入的商品编号不存在")

else:
    print("不是数字请重新输入")
